<template>
    <h1>科室添加</h1>
    <table class="table" border="1">
        <tbody>
            <tr>
                <td>科室名称</td>
                <td>
                    <input type="text" v-model="Info.kName"/>
                </td>
            </tr>
            <tr>
                <td>科室创建时间</td>
                <td>
                    <input type="date" v-model="Info.kCreDate"/>
                </td>
            </tr>
            <tr>
                <td>科室人数</td>
                <td>
                    <input type="text" v-model="Info.kSumPeo"/>人
                </td>
            </tr>
            <tr>
                <td>科室介绍</td>
                <td>
                    <textarea v-model="Info.kJieShao">

                    </textarea>
                </td>
            </tr>
            <tr>
                <td colspan="2" style="text-align: center;">
                    <input type="button" value="保存" @click="Add"/>
                </td>
            </tr>
        </tbody>
    </table>
</template>

<script setup lang="ts">
import { ref } from "vue";
import axios from "axios";
import { useRouter } from "vue-router";

const Info=ref({
    "kId": 0,
  "kName": "",
  "kCreDate": "",
  "kSumPeo": "",
  "kJieShao": "",
  "isDel": 0
})

const router=useRouter();
const Add=()=>{
    axios.post("https://localhost:7199/api/KeRoom/Add",Info.value)
    .then(res=>{
        if(res.data==-1){
            alert("用户名已存在！");
        }
        else if(res.data>0){
            alert("添加成功！")
            router.push("/ShowKeRoom")
        }
        else{
            alert("添加失败")
        }
    })
    .catch(error=>{
        console.log(error);
    })
}
</script>